package com.hksj.mqtt.listener;

import com.hksj.mqtt.client.IMqttClient;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

public class ListenerMqttClientSupport implements ApplicationContextAware {

    private ApplicationContext applicationContext;

    private IMqttClient mqttClient;

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.applicationContext = applicationContext;
    }

    public IMqttClient getMqttClient(){
        if (mqttClient == null){
            mqttClient = applicationContext.getBean(IMqttClient.class);
        }
        return mqttClient;
    }

    public ApplicationContext getApplicationContext() {
        return applicationContext;
    }
}
